import 'whatwg-fetch'
import 'es6-promise'


// import '../mock/wallet/data.js'
// 将对象拼接成 key1=val1&key2=val2&key3=val3 的字符串形式
function obj2params(obj) {
    var result = '';
    var item;
    for (item in obj) {
        result += '&' + item + '=' + encodeURIComponent(obj[item]);
    }

    if (result) {
        result = result.slice(1);
    }

    return result;
}

// 发送 post 请求
export function post(url,paramsObj,isForm) {
    var config = {
        method: 'POST',
        credentials: 'include',
        headers: {
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(paramsObj)
    }
    if (isForm) {
     config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
     config.body = obj2params(paramsObj)
 }
 var result = fetch(url, config);

 return result;
}
